package com.youku.util;

import java.lang.reflect.InvocationTargetException;

public class ReflectHelper {

	public static <T> T newInstance(Class<T> targetClass, Class<?>[] paramTypes, Object[] params) {
		if (targetClass == null)
			throw new NullPointerException("需要创建对象的目标类" + targetClass + "不能为空");

		try {
			return targetClass.getConstructor(paramTypes).newInstance(params);
		} catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException
				| NoSuchMethodException | SecurityException e) {
			throw new RuntimeException("创建targetClass对象失败" + e);
		}
	}
}
